I've a previously created DB with sfDoctrineGuard tables and also two more tables: almunos and socios. I'm trying to run the task
symfony doctrine:build-schema
and aparently seems to work but surprise only the tables related to sfDoctrineGuard plugin appears and not the others two. Why? Did I miss something? What I'm doing wrong?
As the task description says:
The doctrine:build-schema task introspects a database to create a
schema:
./symfony doctrine:build-schema
The task creates a yml file in config/doctrine.
So you have to look inside the folder config/doctrine to check the generated schema.yml.
Related
I'm using Sequel::Model. My model has a set_schema block and a create_table call, so the database is completely managed by the model. The database is sqlite.
I'm trying to add columns to the database and I can't find a way to. Adding fields to the schema has no effect. Adding a migration or an alter_table call doesn't do anything. I've asked on IRC and read the docs. I can't find an example of anyone doing this, but it seems simple.
How do I add a column/field to a Sequel Model?
I did a bunch of research and talked to Jeremy Evans. I was going about this wrong. The right way to do this was to remove my schema plugin code and create_table block and move to using migrations. The steps I went through were:
Remove the schema code (create_table, set_schema) from my modesl
Dump the schema from my current sqlite data files into initial migrations into migration files via the sequel -d command
Create a new migration that adds the columns I need via add_column calls in an alter_table block in a change block
Apply the migrations via the sequel -m command
Create rake tasks to run the migrations and hook those tasks into my deploy tasks
I have created a datatbase "testschema" and schema called "MySchema". I have
created a table "MySchema.table1" in the database. I am trying to create sql
cache dependancy on table using aspnet_regsql utitlity.
MySchema.Table1
But it throw an error.
Enabling the table for SQL cache dependency.
An error has happened. Details of the exception:
Cannot create trigger
'dbo.MySchema.Table1_AspNet_SqlCacheNotification_Trigger'
as its schema is different from the schema of the target table or view.
Failed during cache dependency registration.
Please make sure the database name and the table name are valid. Table names
mus
t conform to the format of regular identifiers in SQL.
The failing SQL command is:
dbo.AspNet_SqlCacheRegisterTableStoredProcedure
I have tried with out schema name and again it is failed. Pl. let me know
what's wrong creating dependancy on table?
Found it !
http://forums.asp.net/t/1249281.aspx/1
The problem occured if you have more other schema on your db (other than [dbo])
after the change made to the sp AspNet_SqlCacheRegisterTableStoredProcedure
to select the schema dynamically it worked!
Thank you Vivek
I'm a bit lost how I should get the entity framework to work with automatic migration. I want:
The database to be created automatically when it doesnt exist
The database to be updated automatically when the model changed
For the latter I'm using DbMigrator. It is rather slow so I don't want to run it every request, and also I have multiple databases in the same application so it cant go in Application_Start which is why I put it in Session_Start like this:
if (Session["started"] == null)
{
// this takes care of any database updates that might be necessary.
MigrationConfiguration configuration = new MigrationConfiguration();
DbMigrator migrator = new DbMigrator(configuration);
List<string> pm = migrator.GetPendingMigrations().ToList();
if (pm.Count > 0)
{
migrator.Update();
}
}
else
{
Session["started"] = "started";
}
Not sure if this is the right way to do it but it seems to work, however it doesnt actually generate the database when it doesnt exist. It gives me a "Cannot open database "db" requested by the login"
I had this working before with the following:
Database.SetInitializer<DbContext>(new InitializerIfModelChange());
This drops the database and generates seed data which is fine for when the database doesnt exist but it also is triggers when the database is changed (in which case I would like DbMigrator to handle it) This was in Application_Start before but I'm not sure what to do with it. I'm afraid that it will conflict with the DbMigrator. How would I set this all up in order to achieve the two things described earlier?
I manually run the Update-Database in the package manager whenever the database needs to be changed. Initially I used the Database.SetInitializer like you did to create the database but have it commented out now.
Checkout Entity Framework 4.3 Automatic Migrations Walkthrough for more advanced help.
This should work for what you want, then if you need to create a new database just add Database.SetInitializer<NewDBContext>(new NewDBInitializer()); like you had, build and run. Then comment it out so it doesn't run in the future on a model change and instead use the Update-Database command in the package manager.
I am currently trying to setup an ASP.Net MVC 3 Application for the first time. I know what I am doing with Ruby on Rails but completely lost with ASP.Net. I would like the app to create the database but not sure what I am doing wrong. I have an empty Database build called ssDB. I have setup the connectionStrings and built out the Model classes. According to everything I have read thus for, when I go to the run the App it should create the database but it doesn't look that way.
The Abbreviated Error I get is:
InnerException: System.Data.SqlClient.SqlException
Message=Invalid object name 'dbo.Users'.
Source=.Net SqlClient Data Provider
ErrorCode=-2146232060
Class=16
LineNumber=1
Number=208
Procedure=""
Server=TESTSVR01
State=1
I have an empty Database build called ssDB
You have created an empty database with no tables. Since there is a database EF assumes tables are also created. Hence it will not proceed to create the tables.
You can drop the database and allow EF to create the database and the tables.
I also experienced the same issue while using Database first approach. Connection string in my service's/service's host web.config was incorrect. I corrected the connection string and it worked.
I have generated Entities files, Proxies files and Tables/fields in database via .yml file schema. I would like to add one more field in schema file.
How can I regenerate Entities, Proxies and MySQL tables/fields via command line tool without dropping tables and deleting all records?
I tried with these and does not work (I am getting error):
./doctrine orm:schema-tool:create
./doctrine orm:schema:tool:update
What did I miss?
I have found a solution:
With this command orm:schema-tool:update --force you add/remove/update fields in database without dropping all records. But firstly you need to change YAML file and Entity class.