File tree Expand file tree Collapse file tree 1 file changed +8
-3
lines changed Expand file tree Collapse file tree 1 file changed +8
-3
lines changed Original file line number Diff line number Diff line change @@ -29,14 +29,19 @@ A Simple Example
2929
3030    from  flask import  Flask 
3131    from  flask_sqlalchemy import  SQLAlchemy 
32+     from  sqlalchemy.orm import  DeclarativeBase, Mapped, mapped_column 
3233
3334    app =  Flask(__name__ ) 
3435    app.config[" SQLALCHEMY_DATABASE_URI" =  " sqlite:///example.sqlite"  
35-     db =  SQLAlchemy(app) 
36+ 
37+     class  Base (DeclarativeBase ): 
38+       pass  
39+ 
40+     db =  SQLAlchemy(app, model_class = Base) 
3641
3742    class  User (db .Model ): 
38-         id   =  db.Column (db.Integer, primary_key = True ) 
39-         username  =  db.Column (db.String, unique = True , nullable = False ) 
43+         id : Mapped[ int ]  =  mapped_column (db.Integer, primary_key = True ) 
44+         username: Mapped[ str ]  =  mapped_column (db.String, unique = True , nullable = False ) 
4045
4146    with  app.app_context(): 
4247        db.create_all() 
 
 
   
 
     
   
   
          
    
    
     
    
      
     
     
    You can’t perform that action at this time.
  
 
    
  
    
      
        
     
       
      
     
   
 
    
    
  
 
  
 
     
    
0 commit comments